const promise = require('../../utils/request.js');
const app = getApp()
const unionId = wx.getStorageSync('unionId')
const util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    promise.sendRequest('account/posList/' + unionId, 'Get', '', null, 4, {
      success: function(data) {
        console.log(data)
        for (let i = 0; i < data.length; i++) {
          if (data[i].timelimit){
           data[i].timelimit = util.formatTime(new Date(data[i].timelimit)).slice(0,11)
         }
          console.log(data[i].timelimit)
          if (data[i].serverUrl) {
            let serverUrl = data[i].serverUrl.indexOf("hui")
            if (serverUrl != -1) {
              data[i].type = '测试'
            } else {
              let serverUrl = data[i].serverUrl.indexOf("p9")
              if (serverUrl != -1) {
                data[i].type = '白菜私有云'
              } else {
                let serverUrl = data[i].serverUrl.indexOf("baicai")
                if (serverUrl != -1) {
                  data[i].type = '白菜公有云'
                } else {
                  data[i].type = '自定义'
                }
              }
            }
          }
        }
        that.setData({
          list: data
        })
      }
    }, {
      fail: function(res) {
        promise.showModule(res);
      }
    })
  },
  toModify(e) {
    let that = this
    let item = e.currentTarget.dataset.index
    wx.navigateTo({
      url: '../modify/modify?address=' + item.address + '&type=' + item.type + '&sn=' + item.sn + '&name=' + item.name + '&serverUrl=' + item.serverUrl + '&timelimit=' + item.timelimit + '&nickName=' + item.nickName
    })
  }
})